import React, { useContext } from 'react';
import { ConfigProvider, Upload as AntdUpload } from 'antd';
import type { UploadProps as AntdUploadProps } from 'antd';
import { useUploadStyles } from './style';
import { uploadThemeConfig } from '../../themes/upload';

// 导出样式扩展 Hook，方便用户使用特殊效果
export { useUploadStyles } from './style';

export interface UploadProps extends AntdUploadProps {
  // 继承所有 antd Upload 属性，无需额外属性
}

const UploadComponent: React.FC<UploadProps> = ({ 
  className,
  ...restProps 
}) => {
  const { styles, cx } = useUploadStyles();
  const context = useContext(ConfigProvider.ConfigContext);
  
  // 合并样式：基础样式 + 用户样式
  const uploadClassName = cx(
    styles.enhancedUpload,      // 基础样式增强
    className                    // 用户自定义样式
  );

  return (
    <ConfigProvider
      theme={{
        components: {
          Upload: {
            ...uploadThemeConfig,
            ...context?.theme?.components?.Upload,
          },
        },
      }}
    >
      <AntdUpload 
        className={uploadClassName} 
        {...restProps} 
      />
    </ConfigProvider>
  );
};

const Upload = Object.assign(UploadComponent, {
  Dragger: AntdUpload.Dragger,
  LIST_IGNORE: AntdUpload.LIST_IGNORE,
});

export { Upload };
export default Upload;

